/*
 * ParagraphDetector.cpp
 *
 *  Created on: Feb 6, 2015
 *      Author: phong
 */

#include "PDCGRNNTrainer.h"

#include <fstream>
#include <string>
using namespace std;

PDCGRNNTrainer::PDCGRNNTrainer() : CGRNNTrainer() {}

PDCGRNNTrainer::~PDCGRNNTrainer() {}

void PDCGRNNTrainer::eval(CGRNN* net, Container* cp) {
	PDCorpus* test = (PDCorpus*)cp;

	ofstream f("/tmp/data." + std::to_string(test->size()) + ".txt");
	for (PDENTRY entry : test->storage) {
		real score = std::get<0>(entry);
		Deptree* tree1 = std::get<1>(entry);
		Deptree* tree2 = std::get<2>(entry);

		net->compForward(tree1);
		net->compForward(tree2);

		f << (score == 1 ? "+1 " : "-1 ");
		for (int i = 0; i < net->dim; i++)
			f << i+1 << ":" << tree1->cRep[0]->data[i] - tree2->cRep[0]->data[i] << " ";
		f << endl;

		tree1->freeTempArrays();
		tree2->freeTempArrays();
	}
	f.close();
}





